package P059_StringSort;

import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;

/**
 * Desc:&emsp;&ensp;对字符串排序持一种宽容的态度
 *
 * @author 李渊&emsp;liyuan7@yusys.com.cn
 * @version 1.0
 * @since V4.3&emsp;2022/3/24
 */
public class StringSort {
    @Test
    public void Test1() {
        String[] strs = {"张三（Z）","李四（L）","王五（W）"};
        // 默认升序
        Arrays.sort(strs);
        int i = 0;
        for (String str:strs){
            System.out.println(++i+"、"+str);
        }

    }
    @Test
    public void Test2() {
        String[] strs = {"张三（Z）","李四（L）","王五（W）"};
        Comparator c = Collator.getInstance(Locale.CHINA);
        Arrays.sort(strs,c);
        int i = 0;
        for (String str:strs){
            System.out.println(++i+"、"+str);
        }

    }

    @Test
    /**
     * java中的中文unicode是基于GB18030，后者是基于GB2312（GBK也是基于此扩充）扩充的，
     * GB2312已经按拼音排好了7000多个字符，之后再扩充就不能插入进去，应该是再末尾
     */
    public void Test3() {
        String[] strs = {"犇（Ben）","鑫（Xin）"};
        Comparator c = Collator.getInstance(Locale.CHINA);
        Arrays.sort(strs,c);
        int i = 0;
        for (String str:strs){
            System.out.println(++i+"、"+str);
        }

    }
}
